﻿using System;
using System.Data;
using System.Reflection;


namespace LG.Common
{
    public static class EnumHelper<TEnum>
    {
        public static DataTable GetDataTable()
        {
            Type enumType = typeof(TEnum);
            if (enumType.IsEnum)
            {
                
                FieldInfo[] enumFields = enumType.GetFields();
                DataTable dt = new DataTable();
                dt.Columns.Add("Name", typeof(string));
                dt.Columns.Add("Value", typeof(int));
                Array arrValues=Enum.GetValues (enumType);
                foreach (object o in arrValues)
                {
                    DataRow dr = dt.NewRow();
                    dr[0] = Enum.GetName(enumType, o);
                    dr[1] = o;
                    dt.Rows.Add(dr);
                }

                /*
                foreach (FieldInfo field in enumFields)
                {
                    if (!field.IsSpecialName)
                    {
                        DataRow dr = dt.NewRow();
                        dr[0] = field.Name;
                        dr[1] = Convert.ToInt32(field.GetRawConstantValue());
                        dt.Rows.Add(dr);
                    }
                }
                 * */
                return dt;
            }
            return null;
        }
    }
}
